/*
 * Licensed to the anubis
 *
 * Copyright (c) 2023 .
 * All rights reserved.
 * 项目名称：anubis-demo-web
 * 项目描述：基于spring5的spring-mvc新特性
 * 版权说明：本软件属XXX有限公司所有，在未获得XXX有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.anubis.demo.web.config;

import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.thymeleaf.spring5.ISpringTemplateEngine;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

/**
 * 此处参考：
 * https://blog.csdn.net/Chen_RuiMin/article/details/104291623
 */
@Configuration
//@ComponentScan用来扫描和发现指定包及其子包中的被@Component（@Service、@Controller）定义
@ComponentScan(basePackages = {"com.anubis.demo.service"})
//@EntityScan用来扫描和发现指定包及其子包中的Entity定义
@EntityScan(basePackages = {"com.anubis.demo.dao.dataobject"})
//@EnableJpaRepositories用来扫描和发现指定包及其子包中的Repository定义
@EnableJpaRepositories(basePackages = {"com.anubis.demo.dao"})
public class AppConfig {

    /**
     * ...
     */
    @Bean
    public ThymeleafViewResolver thymeleafViewResolver(ISpringTemplateEngine engine) {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(engine);
        resolver.setCharacterEncoding("UTF-8");
        return resolver;
    }

    /**
     * ...
     */
    @Bean
    public PasswordEncoder passwordEncoder() {
        return PasswordEncoderFactories.createDelegatingPasswordEncoder();
    }

}
